import ajax from "./pcof/ajax";

//语音录制识别、拍照、图库操作API授权
let data = {
    url: window.location.href.split('#')[0]
};

class WechatOperation {
    install(Vue) {
        let wechatOperation = this;
        Vue.mixin({
            create() {
                this.$wechatOpertion = wechatOperation
            }
        })
    }

    constructor() {

    }

    getRealUrl(url) {
        return data = url.encode(data);
    }

    wxJaAPIInit(url) {
        //'${baseURL}${URL}'
        ajax.post(url, data)
            .then(res => {
                res = realurl.decode(res.code);
                console.log(res);
                this.weInit(res.data)
            })
    }

    /**
     * AppId:wx0bd276a3364f45f6
     * AppSecret:77046aca5287302e77faff69a9fe0434
     * jsApiList:
     * 图片接口：    拍照或从手机相册中选图接口、预览图片接口、获取本地图片接口
     * 音频接口：    开始录音接口、停止录音接口、监听语音播放完毕接口、识别音频并返回识别结果接口
     * 地理位置：    使用微信内置地图查看位置接口、获取地理位置接口
     * 微信扫一扫:   调起微信扫一扫接口
     * @param wxconf
     * 'getLocalImgData',
     */
    weInit(wxconf) {
        wx.config({
            debug: false,
            appId: wxconf.appid,
            timestamp: wxconf.timestamp,
            nonceStr: wxconf.nonceStr,
            signature: wxconf.signature,
            jsApiList: [
                'chooseImage','previewImage','uploadImage',
                'startRecord','stopRecord','onVoicePlayEnd','translateVoice',
                'openLocation','getLocation',
                'scanQRCode',
            ]
        });

        wx.ready(function () {
            console.log("wx ready")
        });

        wx.error(function (res) {
           console.log(res)
        });
    };


}

const wechatOperation = new WechatOperation();

export default wechatOperation